import {createStore} from 'vuex';

export default createStore({
    //state主要存共享数据
    state: {
        count: 0
    },
    //mutations主要存操作数据的方法
    mutations: {
        incrementN(state,payload) {
            state.count+=payload;
        },
        subtraction(state) {
            state.count--;
        },
    },
    //主要存异步方法
    actions: {
        havaReturnAsync() {
            return new Promise((resolve) => {
                setTimeout(() => {
                    resolve(999);
                }, 3000);
            });
        },
        havaReturnAsync1(context, payload) {
            return new Promise((resolve) => {
                setTimeout(() => {
                    resolve(payload);
                }, 3000);
            });
        }
    },
    //主要用来获取数据
    getters: {
        doubleCount: (state) => {
            return state.count * 2;
        }
    },
});